05. Create the Local Project

Now that you have the Firebase CLI installed, you'll use it to set up our local project files on your computer.

Login with Firebase CLI

The first thing you need to do is use the firebase login command. This authenticates the command line tool to your Firebase account.

It'll open up a browser window to the login flow so you can approve it.

Next, set up our local project files.

Initialize Project Directory

Create a new directory called FriendlyChatFunctions and go to it. Here's an example of creating the directory in the Desktop:

$ mkdir ~/Desktop/FriendlyChatFunctions
$ cd ~/Desktop/FriendlyChatFunctions

Now, create your project with the following command to set up a starter template for the Firebase SDK for Cloud Functions in your directory:

$ firebase init functions

You'll be asked to pick one of your Firebase Projects to associate with this project directory. Use the up and down arrow keys to select the FriendlyChat project, and press Enter to select it. Any Cloud Functions you deploy here will be associated with this project. This means you can create Cloud Functions that trigger from Realtime Database events and Storage events from FriendlyChat.

You'll also be prompted to install dependencies from the node package manager, so do that by entering Y to install those dependencies.

Once the dependencies have been installed you now have a functions directory.

In the index.js file you will write any Cloud Function for Firebase in the functions folder. Other files were created too; you can get the full details of what's been created in the functions documentation.

Next, let's talk about the structure of any cloud function before you begin writing one on your own.